import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.Color;
import java.util.ArrayList;
public class Enemy extends Bug{
	private int currentHealth, maxHealth, speed;
	private int moveLoc;
	private ArrayList<Location> path;
	public Enemy(ArrayList<Location> path){
		this.maxHealth = 10;
		currentHealth = maxHealth;
		this.speed = 1;
		this.path = path;
		setHealthColor();
		moveLoc = 0;
	}
	public Enemy(int health, ArrayList<Location> path){
		this.maxHealth = health;
		currentHealth = maxHealth;
		this.speed = 1;
		this.path = path;
		setHealthColor();
		moveLoc = 0;
	}
	public void setHealthColor(){
		if(currentHealth <= maxHealth * 0.2){
			setColor(Color.RED);
		}else if(currentHealth <= maxHealth * 0.4){
			setColor(Color.ORANGE);
		}else if(currentHealth <= maxHealth * 0.6){
			setColor(Color.YELLOW);
		}else if(currentHealth <= maxHealth * 0.8){
			setColor(Color.GREEN);
		}else{
			setColor(Color.BLUE);
		}
	}
	public void setSpeed(int speed){ 
		this.speed = speed; 
	}
	public int getSpeed(){ 
		return speed; 
	}
	public void setMaxHealth(int health){ 
		this.maxHealth = health; 
		setCurrentHealth(health);
	}
	public void setCurrentHealth(int health){ 
		this.currentHealth = health; 
		setHealthColor();
	}
	public int getCurrentHealth(){ 
		return currentHealth; 
	}
	public int getMaxHealth(){
		return maxHealth;
	}
	public void act(){ 
		if(moveLoc >= path.size()){ 
			removeSelfFromGrid();
		}else{ 
			move();
			moveLoc++; 
		}
	}
	public void move(){
		setDirection(getLocation().getDirectionToward(path.get(moveLoc)));
		moveTo(path.get(moveLoc));
	}
	public void takeDamage(){
		currentHealth--;
		setHealthColor();
		if(currentHealth <= 0){
			die();
		}
	}
	public void takeDamage(int dmg){
		for(int i = 0; i < dmg; i++){ 
			takeDamage();
			if(getLocation() == null){
				return;
			}
		}
	}
	public void die(){
		removeSelfFromGrid();
		//add maxHealth
	}
}

